﻿@using ZBJF.Warranty.WebProvider
@using ZBJF.Warranty.Common.Enums.Data
@using ZBJF.Warranty.Common.Enums.InsuranceOrder.Data
@model ZBJF.Warranty.Model.ViewModel.InsuranceProducts.InsuranceProductsModel
@{
    ViewBag.Title = "产品列表";
}
@section Header{
    @Scripts.Render("~/bundles/datatable")
    @Styles.Render("~/Content/datatable")
}
<ul class="nav nav-tabs">
    <li class="active"><a href="/InsuranceProducts/">基础产品列表</a></li>
    <li class="Add-R"><a href="/InsuranceProducts/AddInsuranceProductsBase?id=0">新建基础产品</a></li>
</ul>
<form id="searchForm" class="breadcrumb form-search">
    <table class="keep-all">
        <tr>
            <td>保险产品名称：</td>
            <td>
                @Html.TextBoxFor(m => m.ProductName, new { maxlength = 20, @class = "input-small" })
            </td>
            <td>保额：</td>
            <td>
                @Html.TextBoxFor(m => m.CoverageStart, new { maxlength = 20, @class = "input-small" })<span>至</span>
                @Html.TextBoxFor(m => m.CoverageEnd, new { maxlength = 20, @class = "input-small" })<span>元</span>
            </td>
            <td style="padding-top: 10px;">
                <input id="btnSubmit" class="btn btn-primary Search-R" type="button" value="查询" onclick="search()">
                <input id="btnExport" class="btn btn-success Search-R margin-l-10" type="button" value="导出保险产品清单" onclick="ExportData(@Request["InsuranceProductCategory"])">
            </td>
        </tr>
    </table>
</form>
<div class="table-responsive dataTables_wrapper">
    <table id="insuranceProductsList" class="table table-striped table-bordered table-hover">
        <thead>
            <tr>
                <th width="20">序号</th>
                <th width="120">保险产品名称</th>
                <th width="80">产品编码</th>
                <th width="80">保额</th>
                <th width="100">保险期限</th>
                <th width="100">最后修改时间</th>
                <th width="50">是否启用</th>
                <th width="50">操作</th>
            </tr>
        </thead>
    </table>
</div>
@section scripts{
<script src="~/Scripts/moment.js"></script>
    <script type="text/javascript">
        var isSearch = false;
        $(function () {
            var objTable = $("#insuranceProductsList")
                .dataTable({
                    fnDrawCallback: function () {
                        ControlPermissionOperate();
                    },
                    "aaSorting": [[11, "desc"]],
                    "sAjaxSource": "/InsuranceProducts/Index?InsuranceProductCategory=@Request["InsuranceProductCategory"]",
                    aoColumns: [
                    {
                        "mData": null,
                        "bSortable": false,
                        "fnRender": function (nRow) {
                            return nRow.iDataRow + 1;
                        }
                    },
                    {
                        "mData": null, fnRender: function (nRow) {
                            var html = "<a class='Edit-R'  href='/InsuranceProducts/AddInsuranceProductsBase/" + nRow.aData.ID + "' title='edit'>" + nRow.aData.ProductName + "</a>";
                            return html;
                        }
                    },
                    { "mData": "InsuranceProductNo" },
                    { "mData": "Coverage" },
                    {
                        "mData": null, fnRender: function (nRow) {
                            let _h="";
                            if( nRow.aData.PolicyPeriodYear && nRow.aData.PolicyPeriodYear>0)
                                _h +=nRow.aData.PolicyPeriodYear + "年";
                            if( nRow.aData.PolicyPeriodMonth && nRow.aData.PolicyPeriodMonth>0)
                                _h +=nRow.aData.PolicyPeriodMonth + "月";
                            if( nRow.aData.PolicyPeriodDay && nRow.aData.PolicyPeriodDay>0)
                                _h +=nRow.aData.PolicyPeriodDay + "日";
                            return _h ;
                        }
                    },
                    {
                        "mData": null, fnRender: function (nRow) {
                            return moment(nRow.aData.LastModifyTime).format('YYYY-MM-DD HH:mm:ss');
                        }
                    },
                    {
                        "mData": null, fnRender: function (nRow) {
                            return nRow.aData.IsAvailable ? bootStrapOkIncon : bootStrapRemoveIncon;
                        }
                    },
                    {
                        "mData": null, fnRender: function (nRow) {
                            var html = "<a class='Edit-R'  href='/InsuranceProducts/AddInsuranceProductsBase/" + nRow.aData.ID + "' title='edit'><i class='icon-edit'></i></a>";
                            html += "<a class='Edit-R' href=\"javascript:UpdateStatus('" + nRow.aData.ID + "'," + !nRow.aData.IsAvailable + ",'/InsuranceProducts/UpdateInsuranceProducts','insuranceProductsList')\" title='" + (nRow.aData.IsAvailable ? "禁用" : "启用") + "'>" + (nRow.aData.IsAvailable ? bootStrapRemoveIncon : bootStrapOkIncon) + "</a>";
                            return html;
                        }
                    }]
                });
        });

        function search() {
            /*给查询对象赋值*/
            queryParamList.ProductName = $("#ProductName").val();
            queryParamList.InsuranceDeviceType = $("#InsuranceDeviceType").val();
            queryParamList.InsuranceDevice = $("#InsuranceDevice").val();
            queryParamList.InsuranceProductScreenSPTypeId = $("#InsuranceProductScreenSPTypeId").val();
            queryParamList.WaitDays = $("#WaitDays").val();
            queryParamList.CoverageStart = $("#CoverageStart").val();
            queryParamList.CoverageEnd = $("#CoverageEnd").val();
            queryParamList.IsCardProduct = $("#IsCardProduct").val();
            $("#insuranceProductsList").dataTable().fnDraw();
        }

        function ExportData(id) {
            /*导出数据*/
            if (!confirm("确定要导出Excel吗？")) return;
            search();
            //queryParamList.InsuranceProductCategory = id;
            window.location.href = '@Url.Action("ExportInsuranceDetails")?content=' + JSON.stringify(queryParamList);
        }
    </script>
}


